//
//  MiniViewController.m
//  CollTest
//
//  Created by codew on 11/9/21.
//

#import "MiniViewController.h"
#import "MiniViewCell.h"
#import "CPSCAllCategoryViewController.h"
#import "CPSCTagNameDemoVC.h"
#import "BOTest.h"
#import "STTAViewController.h"
#import "CPSCGradualChangeVC.h"
#import "BannerViewController.h"
#import "CPSCPlistDemoVC.h"
#import "CPSCChooseAddressController.h"


#define KValueImageKey @"KValueImageKey"
#define KValueTextKey @"KValueTextKey"
#define KValueVcName @"KValueVcName"


@interface MiniViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) IBOutlet UICollectionView * collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *collectionLayout;
@property (nonatomic, assign) NSInteger indexSelect;
@property (nonatomic, strong)NSMutableArray * dataArray;

@end


static NSString * CellIdentifier = @"MiniViewCell";

@implementation MiniViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
//    BOTest * objBo = [[BOTest alloc] init];
//    objBo.data = YES;
//
//    if (objBo.isActivityOpen) {
//
//        NSLog(@"复制成功???!!!!!!1");
//    }
//
//    objBo.data = NO;
//
//    if (objBo.isActivityOpen) {
//
//        NSLog(@"复制成功???!!!!!!1");
//    }
    
    
    
    [self setupCollectionViewLayout];
    [self setUpMainUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationItem.leftBarButtonItem.customView.hidden = NO;
    self.navigationItem.titleView = [UIView new];
    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
}

- (void)setUpMainUI
{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    NSArray * dictArr = @[
        
        @{
            KValueImageKey:@"ctg1",
            KValueTextKey:@"分类列表",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg2",
            KValueTextKey:@"搜索结果页",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg5",
            KValueTextKey:@"商品名前面标签",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg6",
            KValueTextKey:@"改变状态栏颜色",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg7",
            KValueTextKey:@"渐变啥的",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg8",
            KValueTextKey:@"Banner",
            KValueVcName : @""
        },
        @{
            KValueImageKey:@"ctg9",
            KValueTextKey:@"Banner",
            KValueVcName : @"CPSCPlistDemoVC"
        },
        @{
            KValueImageKey:@"ctg10",
            KValueTextKey:@"lbl显示html",
            KValueVcName : @"LbLHtmlController"
        },
        @{
            KValueImageKey:@"ctg11",
            KValueTextKey:@"省市区选择",
            KValueVcName : @"CPSCChooseAddressController"
        },
        @{
            KValueImageKey:@"ctg12",
            KValueTextKey:@"寻找",
            KValueVcName : @"TNST_FindFriendDemoVC"
        },
        @{
            KValueImageKey:@"ctg13",
            KValueTextKey:@"视频编辑",
            KValueVcName : @"CPSVideoEditDemoController"
        },
        @{
            KValueImageKey:@"ctg14",
            KValueTextKey:@"下拉选择",
            KValueVcName : @"CPSDemoXiaLaController"
        },
        @{
            KValueImageKey:@"ctg14",
            KValueTextKey:@"下拉选择Demo",
            KValueVcName : @"CPSPanGestureSelectDemoVC"
        },
        @{
            KValueImageKey:@"ctg15",
            KValueTextKey:@"录制按钮View",
            KValueVcName : @"RecordingBtnViewController"
        },
        @{
            KValueImageKey:@"ctg13",
            KValueTextKey:@"视频编辑2",
            KValueVcName : @"CPSVideoEditDemo2Controller"
        },
        @{
            KValueImageKey:@"ctg13",
            KValueTextKey:@"视频编辑3",
            KValueVcName : @"CPSVideoEditDemo3Controller"
        },
        
        
    ];
    
    
    self.dataArray = [NSMutableArray array];
    for (NSDictionary *dict in dictArr) {
        
        MiniCCModel * item = [[MiniCCModel alloc] init];
        item.imageN = dict[KValueImageKey];
        item.text = dict[KValueTextKey];
        item.vcName = dict[KValueVcName];
        [self.dataArray addObject:item];
    }
    
    
    
}


- (void)setupCollectionViewLayout
{
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    CGFloat margin = 0;
    CGFloat column = 4;
    CGFloat cellWidth = ScreenWidth / column;
    // VS_EDBottomLabelView的高
    CGFloat cellHeight = cellWidth;
    _collectionLayout.itemSize = CGSizeMake(cellWidth, cellHeight);
    _collectionLayout.minimumInteritemSpacing = margin;
    _collectionLayout.minimumLineSpacing = margin;
    
    _collectionLayout.sectionInset = UIEdgeInsetsMake(0, margin, 0, margin);
    [_collectionLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    // 注册cell
    [_collectionView registerNib:[UINib nibWithNibName:CellIdentifier bundle:nil] forCellWithReuseIdentifier:CellIdentifier];
}


#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MiniCCModel * item = self.dataArray[indexPath.row];
    NSString * name = item.imageN;
    if ( [name isEqualToString:@"ctg1"]) {
        
        CPSCAllCategoryViewController * vc = [[CPSCAllCategoryViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    
    // 商品名前面标签
    if ( [name isEqualToString:@"ctg5"]) {
        
        CPSCTagNameDemoVC * vc = [[CPSCTagNameDemoVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    // 商品名前面标签
    if ( [name isEqualToString:@"ctg6"]) {
        
        STTAViewController * vc = [[STTAViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    //
    
    if ( [name isEqualToString:@"ctg7"]) {
        
        CPSCGradualChangeVC * vc = [[CPSCGradualChangeVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    if ( [name isEqualToString:@"ctg8"]) {
        
        BannerViewController * vc = [[BannerViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    
    if (item.vcName.length > 1) {
        
        NSString *className = item.vcName;
        Class class = NSClassFromString(className);
        if (class) {
            UIViewController *vc = class.new;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return _dataArray.count;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MiniViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
    MiniCCModel * item = self.dataArray[indexPath.row];
    
    [cell updateCellWithItem:item];
    
//    cell.backgroundColor = kCPSCRandomColor;
    return cell;
}
@end
